package com.yzcrm.erp.kms.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.paragetter.Para;
import com.yzcrm.common.annotation.NotNullValidate;
import com.yzcrm.common.annotation.Permissions;
import com.yzcrm.common.config.paragetter.BasePageRequest;
import com.yzcrm.erp.admin.service.AdminFieldService;
import com.yzcrm.erp.crm.common.CrmEnum;
import com.yzcrm.erp.kms.service.KmsCommentService;
import com.yzcrm.swagger.annotation.ActionApi;
import com.yzcrm.swagger.annotation.Api;
import com.yzcrm.swagger.annotation.Param;
import com.yzcrm.swagger.annotation.Params;
import com.yzcrm.utils.R;

/**
 * @author jiang.xue
 * 评论
 */
@Api(remark = "知识库：评论")
public class KmsCommentController extends Controller{

    @Inject
    private AdminFieldService adminFieldService;

    @Inject
    private KmsCommentService kmsCommentService;

    /**
     * 查看评论列表
     */
    @ActionApi(summary = "查看评论列表", remark="查看评论列表")
    @Params({
            @Param(name="label", remark="权限标识（功能名称）101 资源，103 论坛", dataType="int", defaultValue="", required=true),
            @Param(name="resourceId", remark="评论对象Id（论坛贴子Id或者资源Id）", dataType="int", defaultValue="", required=true),
            @Param(name="pid", remark="引用评论id", dataType="int", defaultValue="", required=false),
            @Param(name="page", remark="页码 1开始", dataType="int", defaultValue="", required=false),
            @Param(name="limit", remark="每页数据条数", dataType="int", defaultValue="", required=false)
    })
    public void queryCommentList(BasePageRequest basePageRequest) {

//        JSONObject jsonObject = basePageRequest.getJsonObject().fluentPut("type", CrmEnum.KMS_BBS.getType());
//        basePageRequest.setJsonObject(jsonObject);
        renderJson(kmsCommentService.queryCommentPageList(basePageRequest));
    }

    /**
     * 添加评论
     */
    @ActionApi(summary = "添加评论", remark="添加评论")
    @Params({
            @Param(name="label", remark="权限标识（功能名称）101 资源，103 论坛", dataType="int", defaultValue="", required=true),
            @Param(name="resourceId", remark="评论对象Id（论坛贴子Id或者资源Id）", dataType="int", defaultValue="", required=true),
            @Param(name="content", remark="评论内容", dataType="String", defaultValue="", required=true),
            @Param(name="pid", remark="引用评论id", dataType="int", defaultValue="", required=false)
    })
    public void addComment(BasePageRequest basePageRequest){

        JSONObject jsonObject = JSON.parseObject(getRawData());
        renderJson(kmsCommentService.addComment(jsonObject));
    }

    /**
     * 根据id删除评论
     */
    @ActionApi(summary = "根据id删除评论", remark="根据id删除评论")
    @Params({
            @Param(name="commentIds", remark="评论ID 多个ID,逗号分割", dataType="String", defaultValue="", required=true),
            @Param(name="label", remark="权限标识（功能名称）101 资源，103 论坛", dataType="int", defaultValue="", required=true)
    })
    @NotNullValidate(value = "commentIds", message = "评论id不能为空")
    public void deleteByIds(@Para("commentIds") String commentIds, @Para("label") Integer label) {

        renderJson(kmsCommentService.deleteByIds(commentIds, label));
    }


}
